<?php

class M_master_supplier extends CI_Model {

	function __construct()
	{
		$this->load->database();
	}
	
	// --------------------------------------------------------------------
      /** 
       * function Supplier()       	   
       * @param :	$Proses [1,2,3,4]
	   				$param	[Kondisi Where Query]
	   				$form_data - array
	   *
       * @return Bool - TRUE or FALSE
       */
	    
	function Supplier($proses,$param,$form_data)
	{
		/*Total Kondisi Where Query*/
		$tot_param 	= sizeof($param);
		
		/*Set Default Data*/
		$rows_array = 0;
		$kondisi	= "";
		
		switch ($proses){
		case 1: /*Insert*/
			break;
		case 2: /*Update*/
			break;		
		case 3: /*Delete*/
			break;	
		case 4: /*Select*/
			/*Set Kondisi Where Query*/
			if($tot_param > 0){
				foreach($param as $value)
				{
					/*----------------------
					- Nambah Parametter Kondisi Where Tinggal Di Tambah di Casenya
					------------------------*/
					++$rows_array;
					switch ($rows_array){
					case 1: /*Kode*/
						if(!empty($value)){
							$kondisi=$kondisi."kode='".$value."'";
						}
					
					case 2: /*Nama*/
						if(!empty($value)){
							$kondisi=$kondisi." and like ucase(nama)='%".$value."%'";
						}
					
					}
				}
				/*End Statement SQL*/
				$kondisi=$kondisi.";";				
				$sql = "SELECT * FROM SUPPLIER WHERE ".$kondisi;
			}
			else{
				/* Tanpa Kondisi */
				$sql = "SELECT * FROM SUPPLIER ";
			}
			
			//return $this->db->query($sql)->result();			
			$query = $this->db->query($sql);			
			if ($query->num_rows() > 0){
				foreach( $query->result() as $data ){
					$supplier[] = $data;
				}
				return $supplier;
					
			}			
			break;	
		}
		return FALSE;			
		break;						
	}
	

	
}
?>